﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Dasideen_ProjectMemberMaster_Update')
	BEGIN
		DROP  Procedure  Dasideen_ProjectMemberMaster_Update
	END

GO

CREATE PROCEDURE [Dasideen_ProjectMemberMaster_Update] 
-- =============================================
-- Author:		<Sagar>
-- Create date: <15/06/2015>
-- Description:	<Dasideen_ProjectMemberMaster_Update>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				@ProjectMemberKey int,
				@ProjectMemberUserKey int = NULL,
				@ProjectMemberFirstName varchar(50),
				@ProjectMemberLastName varchar(50) = NULL,
				@ProjectMemberPrimaryEmailID varchar(150),
				@ProjectMemberCodePlexID varchar(50),
				@ProjectMemberSkypeID varchar(50),
				@ProjectMemberMicrosoftID varchar(50) = NULL,
				@ProjectMemberGoogleID varchar(50) = NULL,
				@ProjectMemberTimeZoneReference varchar(50) = NULL,
				@ProjectMemberTimeZoneName varchar(250) = NULL, 
				@ProjectMemberTimeZoneAbbreviation varchar(50) = NULL,
				@ProjectMemberCountryName varchar(150) = NULL,
				@ProjectMemberCityName varchar(150) = NULL,
				@ProjectMemberDateOfJoining datetime = NULL,
				@ProjectMemberIsMemberOfFacebook bit = NULL,

				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_IsDeleted bit = false,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				@ConcurrencyTimeStamp datetime = NULL,

				@Sys_DateOfModification datetime OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	-- ConcurrencyTimeStamp is mandatory and it needs to check if any other user has changed the reord or not	
	IF @ConcurrencyTimeStamp = NULL
	BEGIN
		RAISERROR('Missing @ConcurrencyTimeStamp', 11,1);
	END
	DECLARE @CurrentModificationDate datetime;
	SET @CurrentModificationDate = (SELECT [Sys_DateOfModification] FROM [ProjectMemberMaster] WHERE [ProjectMemberKey] = @ProjectMemberKey);
	If @ConcurrencyTimeStamp != @CurrentModificationDate
	BEGIN
		RAISERROR('Record is Changed by another process', 11,1);
	END
	
	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();
	
    UPDATE	[ProjectMemberMaster]
	SET 
			[ProjectMemberUserKey] = @ProjectMemberUserKey ,
			[ProjectMemberFirstName] = @ProjectMemberFirstName ,
			[ProjectMemberLastName] = @ProjectMemberLastName,
			[ProjectMemberPrimaryEmailID] = @ProjectMemberPrimaryEmailID ,
			[ProjectMemberCodePlexID] = @ProjectMemberCodePlexID ,
			[ProjectMemberSkypeID] = @ProjectMemberSkypeID ,
			[ProjectMemberMicrosoftID] = @ProjectMemberMicrosoftID ,
			[ProjectMemberGoogleID] = @ProjectMemberGoogleID ,
			[ProjectMemberTimeZoneReference] = @ProjectMemberTimeZoneReference ,
			[ProjectMemberTimeZoneName] = @ProjectMemberTimeZoneName ,
			[ProjectMemberTimeZoneAbbreviation] = @ProjectMemberTimeZoneAbbreviation ,
			[ProjectMemberCountryName] = @ProjectMemberCountryName ,
			[ProjectMemberCityName] = @ProjectMemberCityName ,
			[ProjectMemberDateOfJoining] = @ProjectMemberDateOfJoining ,
			[ProjectMemberIsMemberOfFacebook] = @ProjectMemberIsMemberOfFacebook ,

			[Sys_DateOfModification] = @CurrentDataTime,
			[Sys_ModifiedByID] = @Sys_ModifiedByID,
			[Sys_DeleteType] = @Sys_DeleteType,
			[Sys_IsDeleted] = @Sys_IsDeleted,
			[Sys_OrganizationID] = @Sys_OrganizationID,
			[Sys_InitialPrimaryKeys] = @Sys_InitialPrimaryKeys,
			[Sys_WorkstationName] = @Sys_WorkstationName
	 WHERE
		(
			[ProjectMemberKey] = @ProjectMemberKey
		);
		SET @Sys_DateOfModification = @CurrentDataTime;

END
GO
